package main
/*json练习*/
import (
	"encoding/json"
	"errors"
	"fmt"
	"github.com/gin-gonic/gin"
	"github.com/mitchellh/mapstructure"
	"gm/app/util/common"
	"gm/app/util/response"
	"time"
)


type MobileInfo struct {
	Resultcode   string      `json:"resultcode"`
}

type Family struct {
	LastName string
	LastName2 string
}
type Location struct {
	City string
}
type Person struct {
	Family    `mapstructure:",squash"`
	Location  `mapstructure:",squash"`
	FirstName string
}
type user struct {
	id int `1123`
}


type person struct {
	name string
	age  int
}

func printSlice(x []int){
	fmt.Printf("len=%d cap=%d slice=%v\n",len(x),cap(x),x)
}

func main()  {

	fmt.Println(time.Now())
	fmt.Println(time.Now().Unix())
	errors.New("111")
	errors.New("23")
	monday :=common.GetFirstDateOfWeek()
	sunday := common.TimestampToDate(common.DateToTimestamp(monday)+7*86400)
	weekarar:=monday+"-"+sunday
	fmt.Println(weekarar)
	fmt.Println(common.GetFirstDateOfWeek())
	sdate,edate := common.GetMonthBeginEnd(time.Now())

	//currentTime := time.Now()
	//oldTime := currentTime.AddDate(0, 0, (-7)
	//fmt.Println(oldTime.Unix())

	fmt.Println(sdate.Unix())
	fmt.Println(edate)
	fmt.Println(time.Now().Format("2006-01-02 15:04:05"))

	//fmt.Println(timestamp)
	numbers := []int{0,1,2,3,4,5,6,7,8}
	fmt.Println("numbers[1:4] ==", numbers[1:4])
	fmt.Println("numbers[:3] ==", numbers[:3])


//	//a := &user{}
//	//a.id = 111
//	//b := user{}
//	//b.id = 222
//	c := new(user)
////	c.id = 333
//	fmt.Println(c)

}
func p()  {
	input := map[string]interface{}{
		"FirstName": "Mitchell",
		"LastName":  "Hashimoto",
		"LastName2":  "Hashimoto111",
		"City":      "San Francisco",
	}

	var result Person
	err := mapstructure.Decode(input, &result)
	if err != nil {
		panic(err)
	}

	fmt.Printf("%s %s, %s", result.FirstName, result.LastName2, result.City)
}
func b()  {
	jsonStr:= `{
		"resultcode": "200"
	}`
	var result map[string]interface{}
	err:=json.Unmarshal([]byte(jsonStr), &result)
	if err!=nil{
		fmt.Println(err.Error())
	}
	var mobile MobileInfo

	err = mapstructure.WeakDecode(result, &mobile)
	if err!=nil{
		fmt.Println(err.Error())
	}
	fmt.Println(mobile.Resultcode)
}

func Chan(c *gin.Context) {
	utilGin := response.Gin{Ctx: c}
	s:= []int{1,2,1,23,2,3}
	cc := make(chan int) //?为啥不指定通道也不阻塞


	go sum(s[:len(s)/2],cc)
	go sum(s[len(s)/2:],cc)
	//fmt.Println("numbers[1:4] ==", s[:len(s)/2])
	//go ch_a("aa")
	//go ch_b("bb")
	//go ch_c("cc")
	//x, y := <-cc, <-cc // 从通道 c 中接收
	//////
	//fmt.Println(x, y, x+y)
	time.Sleep(100 * time.Millisecond)
	utilGin.Response(-1, "123", nil)

}

func sum(s []int, cc chan int){
	sum :=0
	for _,v :=range s {
		sum +=v
	}

	cc <- sum
}



func ch_a(s string){
	println(s)
}
func ch_b(s string){
	println(s)
}
func ch_c(s string){
	println(s)
}
